﻿namespace com.crownpack.Web
{
    using System;
    using System.Web.UI.HtmlControls;

    public class HtmlLinkControl : HtmlAnchor
    {
        #region Constructors

        public HtmlLinkControl( )
        {
        }

        #endregion Constructors

        #region Properties

        public string OnClick
        {
            get;
            set;
        }

        /// <summary>
        /// This attribute specifies the location of a Web resource, thus defining a link between the current element (the source anchor) and the destination anchor defined by this attribute.
        /// </summary>
        public string WebResource
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        protected override void OnPreRender( EventArgs e )
        {
            if ( string.IsNullOrEmpty( HRef ) )
                this.Attributes.Add( "href", string.IsNullOrEmpty( WebResource ) ? "#" : WebResource );
            if ( !string.IsNullOrEmpty( OnClick ) )
                this.Attributes.Add( "onclick", OnClick );
            this.InnerText = Title;
        }

        #endregion Methods
    }
}